package com.supermap.census.presenter;

import android.text.TextUtils;

import com.supermap.census.app.SharedPreferencesManager;
import com.supermap.census.callBack.OnLoginFinishedListener;
import com.supermap.census.model.LoginModelImpl;
import com.supermap.census.model.intf.ILoginModel;
import com.supermap.census.presenter.intf.ILoginPresenter;
import com.supermap.census.ui.intf.IBaseView;
import com.supermap.census.ui.intf.ILoginView;

/**
 * Created by Administrator on 2017/3/24 0024.
 */

/**
 * 登录的presenter
 */
public class LoginPresenter implements ILoginPresenter {
    private ILoginView iLoginView;
    private ILoginModel iLoginModel;

    public LoginPresenter(IBaseView iBaseView) {
        this.iLoginView = (ILoginView) iBaseView;
        iLoginModel = new LoginModelImpl();
    }

    @Override
    public void checkAccountMsg() {
        String userName = iLoginView.getUserName();
        String passWord = iLoginView.getPassWord();
        if (TextUtils.isEmpty(userName) || TextUtils.isEmpty(passWord)) {
            iLoginView.successOrFalse(false, "用户名或密码为空！");
        } else {
            iLoginModel.login(userName, passWord, new OnLoginFinishedListener() {
                @Override
                public void success() {
                    iLoginView.successOrFalse(true, "登录成功！");

                }

                @Override
                public void fail() {
                    iLoginView.successOrFalse(false, "登录失败！");
                }
            });
        }
    }

    @Override
    public void destory() {
        iLoginView = null;
        iLoginModel = null;
    }
}
